package cn.tedu.tw.xzx.JDBC;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class AppSelect {
    public static void main(String[] args) throws Exception {
        //创建连接
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String username = "root";
        String password = "xzx20001124";

        //建立连接
        Connection connection = DriverManager.getConnection(url, username, password);
        //创建陈述语句
        Statement statement = connection.createStatement();
        //执行查询
        String sql = "SELECT `id`, `username` FROM `user` ORDER BY id";
        ResultSet set = statement.executeQuery(sql);

        while (set.next()) {
            String s = set.getString(1);
            String v = set.getString(2);
            System.out.println("id：" + s + "    username：" + v);
        }
    }
}